import type { ResponseToolkit } from "@hapi/hapi";
import Hapi from "@hapi/hapi";
import { User } from "../../model/index";
import { userSchema } from "../schema/index";
interface user {
  account: string;
  password: string;
  _id: string;
}
let route: Hapi.ServerRoute<Hapi.ReqRefDefaults> = {
  path: "/editUser",
  method: "post",
  handler: async (r: any, h: ResponseToolkit) => {
    try {
      const { id, account, roles } = r.payload;
      await User.updateOne({ _id: id }, { roles, account });
      return {
        data: true,
        code: 200,
        message: "修改成功",
      };
    } catch (error) {
      return error;
    }
  },
  options: {
    payload: {
      parse: true, // 解析请求体
      allow: "application/json", // 允许JSON格式的请求体
    },
    auth: false,
    tags: ["api"],
  },
};
export default route;
